package com.js.rtu;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;

import com.js.rtu.mvp.bean.Cmd02Bean;
import com.js.rtu.mvp.bean.Cmd40Bean;
import com.js.rtu.mvp.bean.base.CommonBean;
import com.js.rtu.mvp.present.Cmd02Presenter;
import com.js.rtu.mvp.present.Cmd40Presenter;
import com.js.rtu.util.BleUtils;
import com.tbruyelle.rxpermissions2.RxPermissions;

import androidx.appcompat.app.AppCompatActivity;
import io.reactivex.disposables.Disposable;

/**
 * Created by wz on 2019/3/29.
 */
public class SplashActivity extends AppCompatActivity {
   private  Disposable permissionDisposable;

    private String[] permissions ={
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission. READ_PHONE_STATE,
            Manifest.permission. BLUETOOTH,
            Manifest.permission.WRITE_EXTERNAL_STORAGE

    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
         permissionDisposable= new RxPermissions(this)
                 .requestEachCombined(permissions)
                 .subscribe(permission -> {
                     if (permission.granted) {
                         //所有权限授予！
                         Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                         startActivity(intent);
                         finish();
                     } else if (permission.shouldShowRequestPermissionRationale) {
                         //至少有一个被拒绝的权限，而不再问任何问题
                         finish();
                     } else {
                         //至少有一个被拒绝的权限再问一次
                         //需要去设置
                         // Denied permission with ask never again
                         // Need to go to the settings
                         startActivity(new Intent(Settings.ACTION_SETTINGS));
                     }

                 });


//        String data="EE EE 30 32 30 30 30 30 30 38 34 00 40 03 03 0C 16 05 11 08 2B 34 15 00 60 00 00 00 16 05 11 08 2C 34 15 00 61 00 00 00 16 05 11 08 2D 34 15 00 61 00 00 00 00 DF FF FF";

//        String data="EE EE 32 32 30 34 31 30 30 31 42 00 02 16 06 0A 0F 29 0A 0C 00 0F 06 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0A 05 27 04 63 09 63 09 61 0F 07 07 0D 02 03 0B 00 0E 00 0D 9B FF FF";
//        String data="EE EE 30 32 30 30 30 30 30 31 B8 00 40 0E 0E 0C 16 06 07 0F 03 34 1E 00 01 01 01 01 16 06 07 0F 04 34 1E 00 01 01 01 01 16 06 07 0F 0C 08 1E 00 88 12 42 40 16 06 07 0F 0C 1B 1E 00 88 12 42 40 16 06 07 0F 0C 1C 1E 00 AC F4 41 40 16 06 07 0F 0C 1E 1E 00 88 12 42 40 16 06 07 0F 0C 20 1E 00 88 12 42 40 16 06 07 0F 0C 22 1E 00 88 12 42 40 16 06 07 0F 0C 24 1E 00 88 12 42 40 16 06 07 0F 0C 25 1E 00 88 12 42 40 16 06 07 0F 0C 27 1E 00 AC F4 41 40 16 06 07 0F 0C 2A 1E 00 88 12 42 40 16 06 07 0F 0C 2C 1E 00 88 12 42 40 16 06 07 0F 0C 2E 1E 00 88 12 42 40 DB 4B FF FF";
//        Cmd40Presenter presenter = new Cmd40Presenter();
//        CommonBean<Cmd40Bean> bean = presenter.paseData(data);
//        presenter.setInfo(bean);

//        String msg="EE EE 32 32 30 34 31 30 30 31 1C 00 40 01 01 0C 16 06 11 0A 1E 37 05 00 00 0F 00 00 83 99 FF FF ";
//                Cmd40Presenter presenter = new Cmd40Presenter();
//        CommonBean<Cmd40Bean> bean = presenter.paseData(msg);
//        presenter.setInfo(bean);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (!permissionDisposable.isDisposed()) {
            permissionDisposable.isDisposed();
        }
    }
}
